package org.maxgroundstation.groundstation.view.map;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Stroke;

import org.maxgroundstation.groundstation.view.overlay.TextDisplayUtil;

/**
 * A map overlay for displaying the map scale.
 * @author Scott Davis
 * 
 * Copyright (C) 2010  Scott Davis
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
public class ScaleMapOverlay implements MapOverlay {

    // The overlay ID.
    public static final String OVERLAY_ID = "Map Scale";
    private static final Color FG_COLOR = Color.GREEN;
    private static final Color BG_COLOR = new Color(0, 0, 0, 127);
    private static final Stroke FG_STROKE = new BasicStroke(2F);
    private static final Stroke BG_STROKE = new BasicStroke(4F);
    
    /**
     * Constructor
     */
    public ScaleMapOverlay() {
        
    }
    
    @Override
    public void drawMapOverlay(String baseMapStyle, Graphics2D g2d, GpsLocation currentLoc, int width, 
            int height, float zoom) {
        
        Stroke saveStroke = g2d.getStroke();
        
        // Draw scale line.
        drawLine(g2d, width - 120, height - 20, width - 20, height - 20);
        drawLine(g2d, width - 120, height - 25, width - 120, height - 15);
        drawLine(g2d, width - 20, height - 25, width - 20, height - 15);
        
        // Draw scale text.
        int textXCenter = width - 70;
        String text = "" + (int) (zoom * 100F) + " m";
        int xPos = textXCenter;
        int yPos = height - 25;
        TextDisplayUtil.drawText(text, xPos, yPos, g2d);
        
        g2d.setStroke(saveStroke);
    }
    
    /**
     * Draw a shape with a background outline.
     * @param g2d the graphics context.
     * @param shape the shape to draw.
     */
    private void drawLine(Graphics2D g2d, int x1, int y1, int x2, int y2) {
        g2d.setStroke(BG_STROKE);
        g2d.setColor(BG_COLOR);
        g2d.drawLine(x1, y1, x2, y2);
        g2d.setStroke(FG_STROKE);
        g2d.setColor(FG_COLOR);
        g2d.drawLine(x1, y1, x2, y2);
    }

    @Override
    public boolean isDraggable() {
        return false;
    }
}